import {
  Get,
  Post,
  FromatDate,
  FromatPushTime,
  TimestampToTime,
  FormPost
} from "./unit";
let url = 'http://61.147.174.111/'
let localUrl = 'http://dz.enjoy-reading.cn:8082/fhbook'
let getFirstUrl = url + '/rest/getFirstLevelColumnList' //一级栏目链接
let getClassUrl = url + 'fh_pubDucResServer/rest/getColumnNameByFColumnId' //分类链接 图书 视听 视听详细列表
let carouselUrl = url + 'fh_pubDucResServer/rest/queryAdvertisingList' //广告链接
let homeListUrl = url + 'fh_pubDucResServer/rest/getRecommendedResourcesList' //主页链接
let periodicalUrl = url + 'fh_pubDucResServer/rest/getCnkiGroupInformation' //获取 分类 期刊列表 报纸列表 期刊详细列表 期刊信息 期刊图书列表
let readuRL = url + 'fh_pubDucResServer/rest/getColumResByColumnId' //获取 悦读列表 图书详细列表
let bookInfoUrl = url + 'fh_pubDucResServer/rest/getBookInfo' //获取 图书信息
let newBookListUrl = url + 'fh_pubDucResServer/rest/getCnkiDetailInformation' //报纸图书列表
let bookSearch = url + 'fh_pubDucResServer/rest/search' //图书搜索
let cityUrl = url + 'fh_pubDucResServer/rest/getUserNames' //获取乡镇
let loginUrl = url + 'fh_pubDucResServer/rest/login' // 首页登录
let noteUrl = url + 'fh_pubDucResServer/rest/queryNoticeList' //获取公告
let readDetailUrl = localUrl + '/article/selectContent'
let noticeDetailUrl = localUrl + '/notice/selectContent'
let bookCodeUrl = 'http://180.97.46.193:8082/fhbook/Qrcode/selectQrcode'
let activityUrl = url + 'fh_pubDucResServer/rest/getSpecialActivitiesList'
let activityDetailsUrl = localUrl + '/activity/selectContent'
let NewVideoListUrl = url + 'fh_pubDucResServer/rest/getCnkiGroupInformation'
let newRecommendList = url + 'fh_pubDucResServer/rest/getNewColumResByColumnId'
//广告链接
let getCarousel = () => {
  return new Promise((resolve, reject) => {
    Post(carouselUrl, {
        inParam: {
          time: FromatDate(new Date().getTime()), //调用时间
          sysCode: "FH_PUBOPE",
          accId: sessionStorage.getItem('accId') || "3",
          orgId: '',
          advertisingPosition: 1,
          key: 8
        }
      })
      .then(result => {
        resolve(result.data)
      })
  })

}
// 获取首页列表
let getHomeList = () => {
  return new Promise((resolve, reject) => {
    Post(homeListUrl, {
        inParam: {
          time: FromatDate(new Date().getTime()), //调用时间
          sysCode: "FH_PUBOPE",
          prePushTime: FromatPushTime(new Date().getTime()),
          resCount: "8",
          userId: sessionStorage.getItem('userId') || "19",
        }
      })
      .then(result => {
        resolve(result.data)
      })
  })

}
//获取分类列表
let getFirstList = () => {
  return new Promise((resolve, reject) => {
    Post(getFirstUrl, {
        inParam: {
          time: FromatDate(new Date().getTime()), //调用时间
          sysCode: "FH_PUBOPE",
          terminalType: '1',
          userId: sessionStorage.getItem('userId') || "19",
        }
      })
      .then(result => {
        resolve(result.data)
      })
  })

}
//获取 分类列表
let getClassList = (resType, columnId) => {
  return new Promise((resolve, reject) => {
    Post(getClassUrl, {
        inParam: {
          time: FromatDate(new Date().getTime()), //调用时间
          sysCode: "FH_PUBOPE",
          terminalType: '1',
          userId: sessionStorage.getItem('userId') || "19",
          accId: sessionStorage.getItem('accId') || "3",
          orgId: sessionStorage.getItem('orgId') || "1",
          columnId: columnId,
          terminalType: resType
        }
      })
      .then(result => {
        resolve(result.data)
      })
  })

}
let getVideoDetailsList = (resType, columnId) => {
  return new Promise((resolve, reject) => {
    Post(getClassUrl, {
        inParam: {
          time: FromatDate(new Date().getTime()), //调用时间
          sysCode: "FH_PUBOPE",
          terminalType: '1',
          userId: sessionStorage.getItem('userId') || "19",
          accId: sessionStorage.getItem('accId') || "3",
          orgId: sessionStorage.getItem('orgId') || "1",
          columnId: columnId
        }
      })
      .then(result => {
        resolve(result.data)
      })
  })

}
//获取 期刊
let getPeriodicalList = (resType, columnId) => {
  return new Promise((resolve, reject) => {
    Post(periodicalUrl, {
        inParam: {
          time: FromatDate(new Date().getTime()), //调用时间
          group: ["type_name"],
          constraint: [],
          userId: sessionStorage.getItem('userId') || "19",
          pageSize: 10,
          currentPage: 1,
          resourceType: resType,
          maxvalue: [],
          sysCode: "FH_PUBOPE"
        }
      })
      .then(result => {
        resolve(result.data)
      })
  })

}
//获取期刊详细列表
let getPeriodicalDetialsList = (resType, columnId, value, currentPage, pageSize) => {
  return new Promise((resolve, reject) => {
    Post(periodicalUrl, {
        inParam: {
          time: FromatDate(new Date().getTime()), //调用时间
          group: ["source"],
          constraint: [{
            "name": "type_name",
            "value": value
          }],
          userId: sessionStorage.getItem('userId') || "19",
          pageSize: pageSize,
          currentPage: currentPage,
          resourceType: resType,
          maxvalue: ["period", "unit", "file_name"],
          sysCode: "FH_PUBOPE"
        }
      })
      .then(result => {
        resolve(result.data)
      })
  })

}
//获取期刊 图书列表
let getperiodicalListList = (resType, value, period, currentPage, pageSize) => {
  return new Promise((resolve, reject) => {
    Post(periodicalUrl, {
        inParam: {
          time: FromatDate(new Date().getTime()), //调用时间
          group: ["external_source_name", "file_name", "external_source_id"],
          constraint: [{
            "name": "source",
            "value": value
          }, {
            "name": "period",
            "value": period
          }],
          userId: sessionStorage.getItem('userId') || "19",
          pageSize: pageSize || 14,
          currentPage: currentPage || 1,
          resourceType: resType,
          maxvalue: [],
          sysCode: "FH_PUBOPE"
        }
      })
      .then(result => {
        resolve(result.data)
      })
  })

}
//获取 报纸图书列表
let getnewspaper_listList = (resType, value, period) => {
  return new Promise((resolve, reject) => {
    Post(newBookListUrl, {
        inParam: {
          time: FromatDate(new Date().getTime()), //调用时间
          queryfield: ["file_name", "external_source_name", "external_source_id"],
          constraint: [{
            "name": "date",
            "value": TimestampToTime(value)
          }],
          userId: sessionStorage.getItem('userId') || "19",
          pageSize: 14,
          currentPage: 1,
          resourceType: resType,
          sysCode: "FH_PUBOPE"
        }
      })
      .then(result => {
        resolve(result.data)
      })
  })

}
// 获取报纸列表
let getNewList = (resType, columnId, currentPage, pageSize) => {
  return new Promise((resolve, reject) => {
    Post(periodicalUrl, {
        inParam: {
          time: FromatDate(new Date().getTime()), //调用时间
          group: ["paper_name"],
          constraint: [],
          userId: sessionStorage.getItem('userId') || "19",
          pageSize: pageSize,
          currentPage: currentPage,
          resourceType: resType,
          maxvalue: ["date", "file_name"],
          sysCode: "FH_PUBOPE"
        }
      })
      .then(result => {
        resolve(result.data)
      })
  })

}
// 获取视频 分类
let getVideoList = (resType, columnId) => {
  return new Promise((resolve, reject) => {
    Post(getClassUrl, {
        inParam: {
          time: FromatDate(new Date().getTime()), //调用时间
          sysCode: "FH_PUBOPE",
          terminalType: '1',
          userId: sessionStorage.getItem('userId') || "19",
          accId: sessionStorage.getItem('accId') || "3",
          orgId: sessionStorage.getItem('orgId') || "1",
          columnId: columnId,
          terminalType: resType
        }
      })
      .then(result => {
        resolve(result.data)
      })
  })

}
//获取 阅读列表
let getReadList = (resType, columnId, currentPage, pageSize) => {
  return new Promise((resolve, reject) => {
    Post(readuRL, {
        inParam: {
          accId: sessionStorage.getItem('accId') || "3",
          currentPage: currentPage,
          terminalType: 1,
          columnId: columnId,
          time: FromatDate(new Date().getTime()), //调用时间
          pageSize: pageSize,
          sysCode: "FH_PUBOPE"
        }
      })
      .then(result => {
        resolve(result.data)
      })
  })

}
// 获取 图书 所属栏目列表
let getBookDetailList = (resType, columnId, currentPage, pageSize) => {
  return new Promise((resolve, reject) => {
    Post(readuRL, {
        inParam: {
          accId: sessionStorage.getItem('accId') || "3",
          currentPage: currentPage,
          terminalType: 1,
          columnId: columnId,
          time: FromatDate(new Date().getTime()), //调用时间
          pageSize: pageSize,
          sysCode: "FH_PUBOPE",
          orgId: sessionStorage.getItem('orgId') || "1"
        }
      })
      .then(result => {
        resolve(result.data)
      })
  })

}
//获取图书信息

let getBookInfoList = (bookId) => {
  return new Promise((resolve, reject) => {
    Post(bookInfoUrl, {
        inParam: {
          bookId: bookId,
          time: FromatDate(new Date().getTime()), //调用时间
          sysCode: "FH_PUBOPE",
          userId: sessionStorage.getItem('userId') || "19"
        }
      })
      .then(result => {
        resolve(result.data)
      })
  })

}
//获取 期刊信息
let getPeriodicalInfoList = (resType, value, currentPage, pageSize) => {
  return new Promise((resolve, reject) => {
    Post(periodicalUrl, {
        inParam: {
          time: FromatDate(new Date().getTime()), //调用时间
          group: ["period"],
          constraint: [{
            "name": "source",
            "value": value
          }],
          userId: sessionStorage.getItem('userId') || "19",
          pageSize: pageSize,
          currentPage: currentPage,
          resourceType: resType,
          maxvalue: [],
          sysCode: "FH_PUBOPE"
        }
      })
      .then(result => {
        resolve(result.data)
      })
  })

}
//获取报纸信息
let getNewInfoList = (resType, value, currentPage, pageSize) => {
  return new Promise((resolve, reject) => {
    Post(periodicalUrl, {
        inParam: {
          time: FromatDate(new Date().getTime()), //调用时间
          group: ["date"],
          constraint: [{
            "name": "paper_name",
            "value": value
          }],
          userId: sessionStorage.getItem('userId') || "19",
          pageSize: pageSize,
          currentPage: currentPage,
          resourceType: resType,
          maxvalue: [],
          sysCode: "FH_PUBOPE"
        }
      })
      .then(result => {
        resolve(result.data)
      })
  })

}
//获取 视频 信息
let getVideoInfoList = (columnId, currentPage, pageSize) => {
  return new Promise((resolve, reject) => {
    Post(readuRL, {
        inParam: {
          "time": FromatDate(new Date().getTime()), //调用时间
          "sysCode": "FH_PUBOPE",
          "columnId": columnId,
          "userId": sessionStorage.getItem('userId'),
          "terminalType": 1,
          "accid": sessionStorage.getItem('accId') || "3",
          "currentPage":currentPage,
          "pageSize": pageSize
        }
        // inParam: {
        //   accId: sessionStorage.getItem('accId') || "3",
        //   currentPage: currentPage,
        //   terminalType: 1,
        //   columnId: columnId,
        //   time: FromatDate(new Date().getTime()), //调用时间
        //   pageSize: pageSize,
        //   sysCode: "FH_PUBOPE",
        //   "userId":"600",
        // }
      })
      .then(result => {
        resolve(result.data)
      })
  })

}

//搜索
let getBookSearch = (resType, resKind, keyword, currentPage, pageSize) => {
  return new Promise((resolve, reject) => {
    Post(bookSearch, {
        inParam: {
          accId: sessionStorage.getItem('accId') || "3",
          currentPage: currentPage || 1,
          terminalType: resType,
          time: FromatDate(new Date().getTime()), //调用时间
          pageSize: pageSize || 5,
          sysCode: "FH_PUBOPE",
          keyword: keyword,
          userId: sessionStorage.getItem('userId') || "19",
          orgId: sessionStorage.getItem('orgId') || "1",
          resKind: resKind
        }
      })
      .then(result => {
        resolve(result.data)
      })
  })
}
//获取乡镇 和 机构
let getCityList = (prov, city, townName, callType) => {
  return new Promise((resolve, reject) => {
    Post(cityUrl, {
        inParam: {
          time: FromatDate(new Date().getTime()), //调用时间
          sysCode: "FH_PUBOPE",
          provinceId: "320000",
          cityId: prov,
          countryId: city,
          townName: townName || '',
          accId: 1,
          callType: callType || "1",
          platformType: "1"
        }
      })
      .then(result => {
        resolve(result.data)
      })
  })
}
let login = (institution, password) => {
  return new Promise((resolve, reject) => {
    Post(loginUrl, {
        inParam: {
          time: FromatDate(new Date().getTime()),
          sysCode: 'FH_PUBOPE',
          userZch: institution,
          password: password || '',
          userType: '4'
        }
      })
      .then(result => {
        resolve(result.data)
      })
  })
}
let getNoteList = (callType, currentPage, pageSize) => {
  return new Promise((resolve, reject) => {
    Post(noteUrl, {
        inParam: {
          time: FromatDate(new Date().getTime()),
          sysCode: 'FH_PUBOPE',
          accId: sessionStorage.getItem('accId') || "3",
          orgId: sessionStorage.getItem('orgId') || "1",
          terminalType: '1',
          callType: callType,
          currentPage: currentPage || 1,
          pageSize: pageSize || 10
        }
      })
      .then(result => {
        resolve(result.data)
      })
  })
}
let getReadDetail = (data) => {
  return new Promise((resolve, reject) => {
    Get(readDetailUrl, data)
      .then(result => {
        resolve(result.data)
      })
  })
}
let getNoticeDetail = (data) => {
  return new Promise((resolve, reject) => {
    Get(noticeDetailUrl, data)
      .then(result => {
        resolve(result.data)
      })
  })
}
let getBookCode = (data) => {
  return new Promise((resolve, reject) => {
    FormPost(bookCodeUrl, 'text=' + '{"type":"1","bookId":' + data.bookId + '}')
      .then(result => {
        resolve(result.data)
      })
  })
}
let getActivityList = (pageSize, currentPage) => { //获取 活动列表
  return new Promise((resolve, reject) => {
    Post(activityUrl, {
        inParam: {
          pageSize: pageSize || 10,
          orgId: sessionStorage.getItem('orgId') || "1",
          time: FromatDate(new Date().getTime()),
          currentPage: currentPage || 1,
          sysCode: 'FH_PUBOPE',
          accId: sessionStorage.getItem('accId') || "3",
          userId: sessionStorage.getItem('userId') || "19"
        }
      })
      .then(result => {
        resolve(result.data)
      })
  })
}
let getActivityDetails = (data) => {
  return new Promise((resolve, reject) => {
    Get(activityDetailsUrl, data)
      .then(result => {
        resolve(result.data)
      })
  })
}
let getNewVideoList = (resType, resourceType) => { //获取最新视频列表
  return new Promise((resolve, reject) => {
    Post(NewVideoListUrl, {
        inParam: {
          terminalType: resType || '8',
          accId: sessionStorage.getItem('accId') || "3",
          time: FromatDate(new Date().getTime()),
          maxvalue: [],
          userId: sessionStorage.getItem('userId') || "19",
          pageSize: 100,
          constraint: [],
          currentPage: 1,
          group: ['type_name'],
          sysCode: 'FH_PUBOPE',
          resourceType: resourceType || '7'
        }
      })
      .then(result => {
        resolve(result.data)
      })
  })

}
let getNewVideoTwoList = (value, pageSize, currentPage) => { //获取最新视频列表
  return new Promise((resolve, reject) => {
    Post(NewVideoListUrl, {
        inParam: {
          terminalType: '8',
          accId: sessionStorage.getItem('accId') || "3",
          time: FromatDate(new Date().getTime()),
          maxvalue: ['file_name'],
          userId: sessionStorage.getItem('userId') || "19",
          pageSize: pageSize || 12,
          constraint: [{
            "name": "type_name",
            "value": value
          }],
          currentPage: currentPage || 1,
          group: ['book_type_code_name'],
          sysCode: 'FH_PUBOPE',
          resourceType: '7'
        }
      })
      .then(result => {
        resolve(result.data)
      })
  })

}
let getNewVideoThreeList = (value, value2, pageSize, currentPage) => { //获取最新视频列表
  return new Promise((resolve, reject) => {
    Post(NewVideoListUrl, {
        inParam: {
          terminalType: '8',
          accId: sessionStorage.getItem('accId') || "3",
          time: FromatDate(new Date().getTime()),
          maxvalue: ['file_name'],
          userId: sessionStorage.getItem('userId') || "19",
          pageSize: pageSize || 12,
          constraint: [{
            "name": "type_name",
            "value": value
          }, {
            "name": "book_type_code_name",
            "value": value2
          }],
          currentPage: currentPage || 1,
          group: ["file_name", "external_source_name", "external_source_id"],
          sysCode: 'FH_PUBOPE',
          resourceType: '7'
        }
      })
      .then(result => {
        resolve(result.data)
      })
  })

}
let getVideoPlayerUrl = (value) => {
  return new Promise((resolve, reject) => {
    Get(localUrl + '/videoUrl/getUrl?filename=' + value)
      .then(result => {
        resolve(result.data)
      })
  })
}
let getAbout = () => {
  return new Promise(((resolve, reject) => {
    Post('http://180.97.46.193/fh_pubDucResServer/rest/getOrgInfoByOrgId', {
        inParam: {
          "sysCode": "FH_PUBOPE",
          "time": FromatDate(new Date().getTime()),
          accId: sessionStorage.getItem('accId') || "3",
        }
      })
      .then(result => {
        resolve(result.data)
      })
  }))
}
let getNewBookRemmodList = () => {
  return Post(newRecommendList, {
    inParam: {
      accId: sessionStorage.getItem('accId') || "3",
      resCount: "15",
      terminalType: "10",
      columnId: sessionStorage.getItem('BookColumnId'),
      time: FromatDate(new Date().getTime()),
      orgId: sessionStorage.getItem('orgId') || "1",
      sysCode: "FH_PUBOPE"
    }
  })
}
export let GetHomeList = getHomeList
export let GetFirstList = getFirstList
export let GetClassList = getClassList
export let GetPeriodicalList = getPeriodicalList
export let GetNewList = getNewList
export let GetVideoList = getVideoList
export let GetReadList = getReadList
export let GetBookDetailList = getBookDetailList
export let GetPeriodicalDetialsList = getPeriodicalDetialsList
export let GetVideoDetailsList = getVideoDetailsList
export let GetBookInfoList = getBookInfoList
export let GetPeriodicalInfoList = getPeriodicalInfoList
export let GetNewInfoList = getNewInfoList
export let GetVideoInfoList = getVideoInfoList
export let GetperiodicalListList = getperiodicalListList
export let Getnewspaper_listList = getnewspaper_listList
export let GetBookSearch = getBookSearch
export let GetCarousel = getCarousel
export let GetCityList = getCityList
export let Login = login
export let GetNoteList = getNoteList
export let GetReadDetail = getReadDetail
export let GetNoticeDetail = getNoticeDetail
export let GetBookCode = getBookCode
export let GetActivityList = getActivityList
export let GetActivityDetails = getActivityDetails
export let GetNewVideoList = getNewVideoList
export let GetNewVideoTwoList = getNewVideoTwoList
export let GetNewVideoThreeList = getNewVideoThreeList
export let GetVideoPlayerUrl = getVideoPlayerUrl
export let GetAbout = getAbout
export let GetNewBookRemmodList = getNewBookRemmodList
